<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>lwIP: Heap and memory pools</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">lwIP
   &#160;<span id="projectnumber">2.1.2</span>
   </div>
   <div id="projectbrief">Lightweight IP stack</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__lwip__opts__mem.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#define-members">Macros</a>  </div>
  <div class="headertitle">
<div class="title">Heap and memory pools<div class="ingroups"><a class="el" href="group__lwip.html">lwIP</a> &raquo; <a class="el" href="group__lwip__opts.html">Options (lwipopts.h)</a> &raquo; <a class="el" href="group__lwip__opts__infrastructure.html">Infrastructure</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:ga4ef345cc270912bd2230b1c5ec51dfc8"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#ga4ef345cc270912bd2230b1c5ec51dfc8">MEM_LIBC_MALLOC</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:ga4ef345cc270912bd2230b1c5ec51dfc8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae93af697d27bbcefa6a28052d90f2f38"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#gae93af697d27bbcefa6a28052d90f2f38">MEMP_MEM_MALLOC</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:gae93af697d27bbcefa6a28052d90f2f38"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaa2f25586972d1cbc1ff0dcdc6f15a1b0"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#gaa2f25586972d1cbc1ff0dcdc6f15a1b0">MEMP_MEM_INIT</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:gaa2f25586972d1cbc1ff0dcdc6f15a1b0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga97343214666ee6dcb18c0bd77b441ea7"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#ga97343214666ee6dcb18c0bd77b441ea7">MEM_ALIGNMENT</a>&#160;&#160;&#160;1</td></tr>
<tr class="separator:ga97343214666ee6dcb18c0bd77b441ea7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga2dcf8c45f945dd0c4301a94700f2112c"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#ga2dcf8c45f945dd0c4301a94700f2112c">MEM_SIZE</a>&#160;&#160;&#160;1600</td></tr>
<tr class="separator:ga2dcf8c45f945dd0c4301a94700f2112c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga27fdd01194a42fc41a7716b72cdb49e3"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#ga27fdd01194a42fc41a7716b72cdb49e3">MEMP_OVERFLOW_CHECK</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:ga27fdd01194a42fc41a7716b72cdb49e3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga0838947193e222a9f46b582e01e5beff"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#ga0838947193e222a9f46b582e01e5beff">MEMP_SANITY_CHECK</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:ga0838947193e222a9f46b582e01e5beff"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae331a198bd06100b90ea020cd5f07f4e"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#gae331a198bd06100b90ea020cd5f07f4e">MEM_OVERFLOW_CHECK</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:gae331a198bd06100b90ea020cd5f07f4e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga90b17afabb93986a162c327ed30bb4d3"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#ga90b17afabb93986a162c327ed30bb4d3">MEM_SANITY_CHECK</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:ga90b17afabb93986a162c327ed30bb4d3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaddca3141bc7037241769eb152b6f89ba"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#gaddca3141bc7037241769eb152b6f89ba">MEM_USE_POOLS</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:gaddca3141bc7037241769eb152b6f89ba"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaba8be68e8fd0716b723ce4569ed89f82"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#gaba8be68e8fd0716b723ce4569ed89f82">MEM_USE_POOLS_TRY_BIGGER_POOL</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:gaba8be68e8fd0716b723ce4569ed89f82"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga69de593b8ffd4f1c249f03e48e11983b"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#ga69de593b8ffd4f1c249f03e48e11983b">MEMP_USE_CUSTOM_POOLS</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:ga69de593b8ffd4f1c249f03e48e11983b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga0a3ef6098813c103e5aba07da76e15e2"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__lwip__opts__mem.html#ga0a3ef6098813c103e5aba07da76e15e2">LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:ga0a3ef6098813c103e5aba07da76e15e2"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<h2 class="groupheader">Macro Definition Documentation</h2>
<a id="ga0a3ef6098813c103e5aba07da76e15e2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0a3ef6098813c103e5aba07da76e15e2">&#9670;&nbsp;</a></span>LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Set this to 1 if you want to free PBUF_RAM pbufs (or call <a class="el" href="mem_8c.html#a65169147c44e9db60d997819af9b455c">mem_free()</a>) from interrupt context (or another context that doesn't allow waiting for a semaphore). If set to 1, mem_malloc will be protected by a semaphore and SYS_ARCH_PROTECT, while mem_free will only use SYS_ARCH_PROTECT. mem_malloc SYS_ARCH_UNPROTECTs with each loop so that mem_free can run.</p>
<p>ATTENTION: As you can see from the above description, this leads to dis-/ enabling interrupts often, which can be slow! Also, on low memory, mem_malloc can need longer.</p>
<p>If you don't want that, at least for NO_SYS=0, you can still use the following functions to enqueue a deallocation call which then runs in the tcpip_thread context:</p><ul>
<li>pbuf_free_callback(p);</li>
<li>mem_free_callback(m); </li>
</ul>

</div>
</div>
<a id="ga97343214666ee6dcb18c0bd77b441ea7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga97343214666ee6dcb18c0bd77b441ea7">&#9670;&nbsp;</a></span>MEM_ALIGNMENT</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEM_ALIGNMENT&#160;&#160;&#160;1</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEM_ALIGNMENT: should be set to the alignment of the CPU 4 byte alignment -&gt; #define MEM_ALIGNMENT 4 2 byte alignment -&gt; #define MEM_ALIGNMENT 2 </p>

</div>
</div>
<a id="ga4ef345cc270912bd2230b1c5ec51dfc8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga4ef345cc270912bd2230b1c5ec51dfc8">&#9670;&nbsp;</a></span>MEM_LIBC_MALLOC</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEM_LIBC_MALLOC&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library instead of the lwip internal allocator. Can save code size if you already use it. </p>

</div>
</div>
<a id="gae331a198bd06100b90ea020cd5f07f4e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae331a198bd06100b90ea020cd5f07f4e">&#9670;&nbsp;</a></span>MEM_OVERFLOW_CHECK</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEM_OVERFLOW_CHECK&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEM_OVERFLOW_CHECK: mem overflow protection reserves a configurable amount of bytes before and after each heap allocation chunk and fills it with a prominent default value. MEM_OVERFLOW_CHECK == 0 no checking MEM_OVERFLOW_CHECK == 1 checks each element when it is freed MEM_OVERFLOW_CHECK &gt;= 2 checks all heap elements every time <a class="el" href="mem_8c.html#af418ade27d91d41e6143dba2cc246b0f">mem_malloc()</a> or <a class="el" href="mem_8c.html#a65169147c44e9db60d997819af9b455c">mem_free()</a> is called (useful but slow!) </p>

</div>
</div>
<a id="ga90b17afabb93986a162c327ed30bb4d3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga90b17afabb93986a162c327ed30bb4d3">&#9670;&nbsp;</a></span>MEM_SANITY_CHECK</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEM_SANITY_CHECK&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEM_SANITY_CHECK==1: run a sanity check after each <a class="el" href="mem_8c.html#a65169147c44e9db60d997819af9b455c">mem_free()</a> to make sure that the linked list of heap elements is not corrupted. </p>

</div>
</div>
<a id="ga2dcf8c45f945dd0c4301a94700f2112c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga2dcf8c45f945dd0c4301a94700f2112c">&#9670;&nbsp;</a></span>MEM_SIZE</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEM_SIZE&#160;&#160;&#160;1600</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEM_SIZE: the size of the heap memory. If the application will send a lot of data that needs to be copied, this should be set high. </p>

</div>
</div>
<a id="gaddca3141bc7037241769eb152b6f89ba"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaddca3141bc7037241769eb152b6f89ba">&#9670;&nbsp;</a></span>MEM_USE_POOLS</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEM_USE_POOLS&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEM_USE_POOLS==1: Use an alternative to malloc() by allocating from a set of memory pools of various sizes. When mem_malloc is called, an element of the smallest pool that can provide the length needed is returned. To use this, MEMP_USE_CUSTOM_POOLS also has to be enabled. </p>

</div>
</div>
<a id="gaba8be68e8fd0716b723ce4569ed89f82"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaba8be68e8fd0716b723ce4569ed89f82">&#9670;&nbsp;</a></span>MEM_USE_POOLS_TRY_BIGGER_POOL</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEM_USE_POOLS_TRY_BIGGER_POOL&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEM_USE_POOLS_TRY_BIGGER_POOL==1: if one malloc-pool is empty, try the next bigger pool - WARNING: THIS MIGHT WASTE MEMORY but it can make a system more reliable. </p>

</div>
</div>
<a id="gaa2f25586972d1cbc1ff0dcdc6f15a1b0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaa2f25586972d1cbc1ff0dcdc6f15a1b0">&#9670;&nbsp;</a></span>MEMP_MEM_INIT</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEMP_MEM_INIT&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEMP_MEM_INIT==1: Force use of memset to initialize pool memory. Useful if pool are moved in uninitialized section of memory. This will ensure default values in pcbs struct are well initialized in all conditions. </p>

</div>
</div>
<a id="gae93af697d27bbcefa6a28052d90f2f38"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae93af697d27bbcefa6a28052d90f2f38">&#9670;&nbsp;</a></span>MEMP_MEM_MALLOC</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEMP_MEM_MALLOC&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator. Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution speed (heap alloc can be much slower than pool alloc) and usage from interrupts (especially if your netif driver allocates PBUF_POOL pbufs for received frames from interrupt)! ATTENTION: Currently, this uses the heap for ALL pools (also for private pools, not only for internal pools defined in <a class="el" href="memp__std_8h.html">memp_std.h</a>)! </p>

</div>
</div>
<a id="ga27fdd01194a42fc41a7716b72cdb49e3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga27fdd01194a42fc41a7716b72cdb49e3">&#9670;&nbsp;</a></span>MEMP_OVERFLOW_CHECK</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEMP_OVERFLOW_CHECK&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEMP_OVERFLOW_CHECK: memp overflow protection reserves a configurable amount of bytes before and after each memp element in every pool and fills it with a prominent default value. MEMP_OVERFLOW_CHECK == 0 no checking MEMP_OVERFLOW_CHECK == 1 checks each element when it is freed MEMP_OVERFLOW_CHECK &gt;= 2 checks each element in every pool every time <a class="el" href="memp_8c.html#a2b00593d086313c267b54a976bf67aa5">memp_malloc()</a> or <a class="el" href="memp_8c.html#aecd94926b7c2a0e23ae195f4ae97581f">memp_free()</a> is called (useful but slow!) </p>

</div>
</div>
<a id="ga0838947193e222a9f46b582e01e5beff"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0838947193e222a9f46b582e01e5beff">&#9670;&nbsp;</a></span>MEMP_SANITY_CHECK</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEMP_SANITY_CHECK&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEMP_SANITY_CHECK==1: run a sanity check after each <a class="el" href="memp_8c.html#aecd94926b7c2a0e23ae195f4ae97581f">memp_free()</a> to make sure that there are no cycles in the linked lists. </p>

</div>
</div>
<a id="ga69de593b8ffd4f1c249f03e48e11983b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga69de593b8ffd4f1c249f03e48e11983b">&#9670;&nbsp;</a></span>MEMP_USE_CUSTOM_POOLS</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MEMP_USE_CUSTOM_POOLS&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h that defines additional pools beyond the "standard" ones required by lwIP. If you set this to 1, you must have lwippools.h in your include path somewhere. </p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
  </ul>
</div>
</body>
</html>
